<template>
	<view>
		<uni-forms ref="form" :rules="{}">
					<uni-forms-item label="" name="">
						<uni-easyinput  v-model="user.username" placeholder="请输入用户名" />
					</uni-forms-item>
					<uni-forms-item label="" name="">
						<uni-easyinput  type="password" v-model="user.password" placeholder="请输入密码"/>
					</uni-forms-item>
					<uni-forms-item label="" name="">
						<button type="primary"@click="login" >登录</button>
					</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
					return {
						user:{
							username:'tom',
							password:'123'
						}
					}
				},
		methods: {
					login(e){
						console.log(e);
						uni.request({
							url: 'http://localhost:8090/foodapp/user/login',
							method: 'POST',
							data: this.user,
							success: res => {
								console.log(res.data);
								if (res.data.success == true) {
									uni.showToast({
										title: res.data.data.username + '登录成功',
										icon:'none'
									});
									
									uni.setStorageSync("userinfo",res.data.data)
									uni.switchTab({
										url:'/pages/my/my'
									})
								} else {
									uni.showToast({
										title: '登录失败',
										icon: 'none'
									});
								}
						
							},
							fail: () => {
								uni.showToast({
									title: '登录失败',
									icon: 'none'
								});
							},
							complete: () => {}
						});
					}
				},
				}
				
</script>

<style>

</style>
